/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.crm.sopm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import merlion.mrp.ppm.entity.Product;
import merlion.scm.icm.entity.InventoryReservation;
import merlion.scm.icm.entity.WarehouseLocation;

/**
 *
 * @author Yuwei
 */
@Entity
public class ItemLine implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Long qtyAvailable;
    private Long qtyOrderedBar;
    private Long qtyOrderedCase;
    private Double unitPriceSGD;
    private Double unitPriceUSD;
    private Double orderDiscount;
    private Double memberDiscount;
    private Double specialDiscount;
    private Double subTotal;
    private Timestamp timeCreated;
    @OneToOne(targetEntity=Product.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Product product;
    @OneToMany(targetEntity = InventoryReservation.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private List<InventoryReservation> reservations; 
    
   

    public ItemLine() {
        qtyAvailable = (long)0;
        qtyOrderedBar = (long)0;
        qtyOrderedCase = (long)0;
        unitPriceSGD = (double)0;
        unitPriceUSD = (double)0;
        orderDiscount = (double)0;
        memberDiscount = (double)0;
        specialDiscount = (double)0;
        subTotal = (double)0;
        product = new Product();
        Random rand = new Random();
        long seed = new Date().getTime() + (long)rand.nextInt(10000);
        timeCreated = new Timestamp(seed);
        reservations = new ArrayList<InventoryReservation>();
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    @Override
    public ItemLine clone(){
        ItemLine i = new ItemLine();
        
        i.setMemberDiscount(this.getMemberDiscount());
        i.setOrderDiscount(this.getOrderDiscount());
        i.setProduct(this.getProduct());
        i.setQtyAvailable(this.getQtyAvailable());
        i.setQtyOrderedBar(this.getQtyOrderedBar());
        i.setQtyOrderedCase(this.getQtyOrderedCase());
        i.setSpecialDiscount(this.getSpecialDiscount());
        i.setSubTotal(this.getSubTotal());
        i.setTotal(this.getTotal());
        i.setUnitPriceSGD(this.getUnitPriceSGD());
        i.setUnitPriceUSD(this.getUnitPriceUSD());
        i.setTimeCreated(new Timestamp(System.currentTimeMillis()));
        
        return i;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ItemLine)) {
            return false;
        }
        
        ItemLine other = (ItemLine) object;
        // Compare timestamp
        if(!this.timeCreated.equals(other.timeCreated))
            return false;
        
        return true;
    }

    @Override
    public String toString() {
        return "merlion.crm.sopm.entity.ItemLine[ id=" + id + " ]";
    }

    /**
     * @return the product
     */
    public Product getProduct() {
        return product;
    }

    /**
     * @param product the product to set
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    public List<InventoryReservation> getReservations() {
        return reservations;
    }

    public void setReservations(List<InventoryReservation> reservations) {
        this.reservations = reservations;
    }
    

    /**
     * @return the qtyAvailable
     */
    public Long getQtyAvailable() {
        return qtyAvailable;
    }

    /**
     * @param qtyAvailable the qtyAvailable to set
     */
    public void setQtyAvailable(Long qtyAvailable) {
        this.qtyAvailable = qtyAvailable;
    }

    public Long getQtyOrderedBar() {
        return qtyOrderedBar;
    }

    public void setQtyOrderedBar(Long qtyOrderedBar) {
        this.qtyOrderedBar = qtyOrderedBar;
    }

    public Long getQtyOrderedCase() {
        return qtyOrderedCase;
    }

    public void setQtyOrderedCase(Long qtyOrderedCase) {
        this.qtyOrderedCase = qtyOrderedCase;
    }

    public Double getUnitPriceSGD() {
        return unitPriceSGD;
    }

    public void setUnitPriceSGD(Double unitPriceSGD) {
        this.unitPriceSGD = unitPriceSGD;
    }

    public Double getUnitPriceUSD() {
        return unitPriceUSD;
    }

    public void setUnitPriceUSD(Double unitPriceUSD) {
        this.unitPriceUSD = unitPriceUSD;
    }

    /**
     * @return the orderDiscount
     */
    public Double getOrderDiscount() {
        return orderDiscount;
    }

    /**
     * @param orderDiscount the orderDiscount to set
     */
    public void setOrderDiscount(Double orderDiscount) {
        this.orderDiscount = orderDiscount;
    }

    public Double getSpecialDiscount() {
        return specialDiscount;
    }

    public void setSpecialDiscount(Double specialDiscount) {
        this.specialDiscount = specialDiscount;
    }

    public Double getTotal() {
        return subTotal;
    }

    public void setTotal(Double total) {
        this.subTotal = total;
    }

    public Double getMemberDiscount() {
        return memberDiscount;
    }

    public void setMemberDiscount(Double memberDiscount) {
        this.memberDiscount = memberDiscount;
    }

    public Double getSubTotal() {
        return subTotal;
    }

    public void setSubTotal(Double subTotal) {
        this.subTotal = subTotal;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    public void setTimeCreated(Timestamp timeCreated) {
        this.timeCreated = timeCreated;
    }
    
}
